home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / ici / ici.cpi / tst-del.ici < prev    next >
Text File  |  1994-10-27  |  865b  |  50 lines

  1. /*
  2.  * Work the del() function with random data.
  3.  */
  4. auto victim    = [struct];
  5. auto state    = [struct];
  6. auto i;
  7. auto e;
  8. auto v;
  9.  
  10. for (i = 0; i < 100; ++i)
  11. {
  12.     switch (int(rand() * 2) % 2)
  13.     {
  14.     case 0:
  15.     /*
  16.      * Add a random element, give it a distinct value, and record
  17.      * that it should be present.
  18.      */
  19.     e = int(rand() * 100);
  20.     victim.(e) = e * 10;
  21.     state.(e) = 1;
  22.     break;
  23.  
  24.     case 1:
  25.     /*
  26.      * Delete a random element, and record that it should be absent.
  27.      */
  28.     e = int(rand() * 100);
  29.     del(victim, e);
  30.     state.(e) = 0;
  31.     break;
  32.     }
  33.     /*
  34.      * Check the state of the victim against the recorded state.
  35.      */
  36.     forall (v, e in state)
  37.     {
  38.     if (v)
  39.     {
  40.         if (victim.(e) != e * 10)
  41.         fail(sprintf("wrong value at pass %d of del() test", i));
  42.     }
  43.     else
  44.     {
  45.         if (victim.(e) != NULL)
  46.         fail(sprintf("value not NULL at pass %d of del() test", i));
  47.     }
  48.     }
  49. }
  50.